**File to create dataset 2

cd "INSERT WORKING DIRECTORY HERE"

use "Hollyer_Rosendorff_PTA_Update.dta", clear
drop  _merge endobserv _st _d _origin _t _t0
sort leader_id ccode year
merge m:1 ccode year using "HRVanalysisJOPPrepped.dta"
drop if _merge~=3
drop _merge

merge m:1 ccode year using "Polity_2014.dta"
drop if _merge~=3
drop _merge
replace polity=. if polity==-88
replace polity=. if polity==-77
replace polity=. if polity==-66

save "CausalMechanism.dta", replace

use "Penn World Tables 8.0.dta", clear
kountry countrycode, from(iso3c) to(cown)
rename _COWN_ ccode
drop if ccode==.

merge 1:m ccode year using "CausalMechanism.dta"
drop if _merge~=3
drop _merge

save "CausalMechanism.dta", replace

**create OECD variable
gen OECD=0

replace OECD=1 if ccode==900 & year>=1971
replace OECD=1 if ccode==305 & year>=1961
replace OECD=1 if ccode==211 & year>=1961
replace OECD=1 if ccode==20 & year>=1961
replace OECD=1 if ccode==155 & year>=2010
replace OECD=1 if ccode==316 & year>=1995
replace OECD=1 if ccode==390 & year>=1961
replace OECD=1 if ccode==366 & year>=2010
replace OECD=1 if ccode==375 & year>=1969
replace OECD=1 if ccode==220 & year>=1961
replace OECD=1 if ccode==255 & year>=1961
replace OECD=1 if ccode==350 & year>=1961
replace OECD=1 if ccode==310 & year>=1996
replace OECD=1 if ccode==395 & year>=1961
replace OECD=1 if ccode==205 & year>=1961
replace OECD=1 if ccode==666 & year>=2010
replace OECD=1 if ccode==325 & year>=1962
replace OECD=1 if ccode==740 & year>=1964
replace OECD=1 if ccode==732 & year>=1996
replace OECD=1 if ccode==212 & year>=1961
replace OECD=1 if ccode==70 & year>=1994
replace OECD=1 if ccode==210 & year>=1961
replace OECD=1 if ccode==920 & year>=1973
replace OECD=1 if ccode==385 & year>=1961
replace OECD=1 if ccode==290 & year>=1996
replace OECD=1 if ccode==235 & year>=1961
replace OECD=1 if ccode==317 & year>=2000
replace OECD=1 if ccode==349 & year>=2010
replace OECD=1 if ccode==230 & year>=1961
replace OECD=1 if ccode==380 & year>=1961
replace OECD=1 if ccode==225 & year>=1961
replace OECD=1 if ccode==640 & year>=1961
replace OECD=1 if ccode==200 & year>=1961
replace OECD=1 if ccode==2 & year>=1961



**do some analysis**

//prep data
sort leader_id ccode year
duplicates drop ccode year, force
xtset ccode year, yearly
eststo clear

//generate variables
gen logNSBIT = log(l.NSBITs+1)
gen PolityNSBIT = l.polity*logNSBIT
gen CGVNSBIT = l.democracy*logNSBIT
gen logGDP = log(l.rgdpo)
gen logGDPPC = log(l.rgdpo/l.pop)
quietly tab year, gen(_yr)

label var logNSBIT "North-South BITs (Logged)"
label var polity "Polity II"
label var PolityNSBIT "North-South BITs*Polity"
label var democracy "CGV Democracy"
label var CGVNSBIT "North-South BIT BITs*CGV"

local controls logGDP logGDPPC _yr*

//run some regressions
quietly eststo HRV1: xtreg fraction_reported logNSBIT polity PolityNSBIT if OECD==0, fe cluster(ccode) robust

quietly eststo HRV2: xtreg fraction_reported logNSBIT polity PolityNSBIT `controls' if OECD==0, fe cluster(ccode) robust

quietly eststo XCONST1: xtreg xconst logNSBIT democracy CGVNSBIT if OECD==0, fe cluster(ccode) robust

quietly eststo XCONST2: xtreg xconst logNSBIT democracy CGVNSBIT `controls' if OECD==0, fe cluster(ccode) robust

esttab HRV1 HRV2 XCONST1 XCONST2 using "CausalMechanism.tex", drop(_yr*) replace tex se label title(Effect of North-South BITs and Regime Type on Economic Reform\label{table:cm}) ///
mtitles("Model 1: HRV Index" "Model 2: HRV Index" "Model 3: Executive Constraints" "Model 4: Executive Constraints")
